package com.nf.health.app.adapter;

import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.nf.health.app.R;
import com.nf.health.app.models.Family;
import com.nf.health.app.utils.ImageLoaderUtils;

import java.util.List;

public class FamilyGridAdapter extends BaseAdapter {

	private List<Family> accounts;
	public FamilyGridAdapter(List<Family> accounts) {
		this.accounts = accounts;
	}
	@Override
	public int getCount() {
		if(accounts != null){
			return accounts.size();
		}
		return 0;
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Family account = accounts.get(position);
		ViewHolder holder = ViewHolder.get(parent, convertView, R.layout.item_grid_family, position);
		ImageView iv_head = holder.getView(R.id.iv_head);
		if(Family.TYPE_SIMPLE.equals(account.getType())){
			ImageLoaderUtils.getinstance(parent.getContext()).getImage(iv_head, account.getHimg(), R.drawable.my_family_icon);
		}else if(Family.TYPE_FAMILY.equals(account.getType())){
			iv_head.setImageResource(R.drawable.myfamily_equip);
		}else if(Family.TYPE_OLD_MOBILE.equals(account.getType())){
			iv_head.setImageResource(R.drawable.myfamily_oldphone);
		}else{
			iv_head.setImageResource(R.drawable.default_head);
		}
		if(TextUtils.isEmpty(account.getNick())){
			holder.setText(R.id.tv_name, account.getAccount());
		}else{
			holder.setText(R.id.tv_name, account.getNick());
		}
		return holder.getConvertView();
	}

}
